home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / pc / windows / qtw_201 / setup / samples / p9000 / p9000v.cpp < prev   
Encoding:
C/C++ Source or Header  |  1994-12-19  |  8.7 KB  |  311 lines

  1. // ---------------------------------------------------------------------
  2. //
  3. // P9000V.CPP    Sample VHDW Component for P9000 chips
  4. //
  5. //               Version 1.0
  6. //
  7. //               (c) Copyright 1988-1994 Apple Computer, Inc. All Rights Reserved.
  8. //
  9. // ---------------------------------------------------------------------
  10.  
  11.  
  12. // Windows header files
  13. // --------------------
  14. #include <windows.h>
  15. #include <windowsx.h>
  16.  
  17.  
  18. // Compiler header files
  19. // ---------------------
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23.  
  24. // QuickTime header files
  25. // ----------------------
  26. #include <qtcodec.h>
  27. #include <qtvhdw.h>
  28.  
  29.  
  30. // Project header files
  31. // --------------------
  32. #include "p9000.h"
  33.  
  34.  
  35. // Assembler functions
  36. // -------------------
  37. extern "C" {
  38.     DWORD QTAPI VHDWEntry (VOID);
  39.     WORD FAR CDECL DispatchP9000 ();
  40. }
  41.  
  42.  
  43. // Local functions
  44. // ---------------
  45. static VOID FAR PASCAL FixupCM (ENTRYFUNC lpfnCM);
  46. static VOID FAR PASCAL FixupTB (ENTRYFUNC lpfnTB);
  47. static HINSTANCE GetInstOfThisMod ();
  48.  
  49.  
  50. // Global data
  51. // -----------
  52. extern "C" ENTRYFUNC lpfnQTComponentManager ;
  53. extern "C" ENTRYFUNC lpfnQTToolbox ;
  54.  
  55.  
  56. // Local data
  57. // ----------
  58. static HINSTANCE hInstThisMod;
  59. static HDWDISP CheckHardware;
  60.  
  61.  
  62. // Local macros
  63. // ------------
  64. #define CURR_VERSION 1
  65.  
  66.  
  67. // Component description
  68. // ---------------------
  69. ComponentDescription cdTable[] =
  70.   { QTFOURCC ('v','h','d','w')
  71.   , QTFOURCC ('s','0','0','2')
  72.   , QTFOURCC ('a','p','p','l')
  73.   , 0
  74.   , 0
  75.   , (ComponentRoutine) VHDWEntry
  76.   , 0
  77.   , 0
  78.   , 0
  79.   };
  80.  
  81.  
  82. // Function cfCanDoSelect: Report if a function is implemented
  83. // -----------------------------------------------------------
  84. extern "C" ComponentResult QTAPI cfCanDoSelect (STKOFF_CMP so, LONG lFunctionSelector) {
  85.  
  86.     // Switch on function selector
  87.     switch (lFunctionSelector) {
  88.         case kComponentOpenSelect:
  89.         case kComponentCloseSelect:
  90.         case kComponentCanDoSelect:
  91.         case kComponentVersionSelect:
  92.         case kComponentRegisterSelect:
  93.         case kComponentTargetSelect:
  94.         case kSniffVideoHardware:
  95.             return TRUE;
  96.         default:
  97.             return FALSE;
  98.     }
  99. }
  100.  
  101.  
  102. // Function cfCloseSelect: Close an open component instance
  103. // --------------------------------------------------------
  104. extern "C" ComponentResult QTAPI cfCloseSelect (STKOFF_CMP so, ComponentInstance ci) {
  105.  
  106.     // Close component free any allocated storage
  107.  
  108.     // Successful return
  109.     return noErr;
  110. }
  111.  
  112.  
  113. // Function cfOpenSelect: Open a component instance
  114. // ------------------------------------------------
  115. extern "C" ComponentResult QTAPI cfOpenSelect (STKOFF_CMP so, ComponentInstance ci) {
  116.  
  117.     // Allocate and register private storage
  118.  
  119.     // Successful return
  120.     return noErr;
  121. }
  122.  
  123.  
  124. // Function RegisterSelect: Return 0 as there is nothing to check before registering
  125. // ---------------------------------------------------------------------------------
  126. extern "C" ComponentResult QTAPI cfRegisterSelect (STKOFF_CMP so, ComponentInstance ci) {
  127.  
  128.     return 0;
  129. }
  130.  
  131.  
  132. // Function SniffVideoHardware
  133. // ---------------------------
  134. extern "C" HDWDISP QTAPI cfSniffVideoHardware (STKOFF_CMP so, ComponentInstance ci,
  135.                                                 BMP_TYPE bmpt, LPSTR lpszCompID, LPSTR lpszHdwID) {
  136.  
  137.     LPSTR lpszPixels;
  138.  
  139.     // Identify component
  140.     lstrcpy (lpszCompID, "Sample P9000 VHDW Component");
  141.  
  142.     // Filter out BMP types not supported by our custom routines
  143.     switch (bmpt)  {
  144.         case BMP_INDEX_8  : lpszPixels = "8-bit palettized"   ; break;
  145.         case BMP_5_5_5    : lpszPixels = "16-bit 555"         ; break;
  146.         case BMP_5_6_5    : lpszPixels = "16-bit 565"         ; break;
  147.         case BMP_5_6_5_M  : lpszPixels = "16-bit 565 Motorola"; break;
  148.         case BMP_8_8_8_RGB: lpszPixels = "24-bit RGB"         ; break;
  149.         case BMP_8_8_8_BGR: lpszPixels = "24-bit BGR"         ; break;
  150.             break;
  151.     default :
  152.         return 0;
  153.     }
  154.  
  155.     // Weitek P9000
  156.     // Typical cards:  Diamond Viper
  157.     CheckHardware = (HDWDISP) DispatchP9000;
  158.     if (CheckHardware (VDSP_IDENTIFY) != 0 && CheckHardware (VDSP_VERSION) == CURR_VERSION) {
  159.         wsprintf (lpszHdwID, "%s pixels; P9000 internal hardware support", lpszPixels);
  160.         return CheckHardware;
  161.     }
  162.  
  163.     // The adapter hardware is not supported
  164.     CheckHardware = 0;
  165.     return 0;
  166. }
  167.  
  168.  
  169. /// Function TargetSelect: Not implemented
  170. // ---------------------------------------
  171. extern "C" ComponentResult QTAPI cfTargetSelect (STKOFF_CMP so, ComponentInstance ci) {
  172.  
  173.     // Successful return
  174.     return noErr;
  175. }
  176.  
  177.  
  178. // Function cfVersionSelect: Return the version of this component
  179. // ----------------------------------------------------------------
  180. extern "C" ComponentResult QTAPI cfVersionSelect (STKOFF_CMP so, ComponentInstance ci) {
  181.  
  182.     // Return an arbitrary non-zero version to the user
  183.     return CheckHardware != NULL? CheckHardware (VDSP_VERSION) : CURR_VERSION;
  184. }
  185.  
  186.  
  187. // Function FixupCM: Establish direct linkage to Component Manager
  188. // ---------------------------------------------------------------
  189. static VOID FAR PASCAL FixupCM (ENTRYFUNC lpfnCM) {
  190.  
  191.     lpfnQTComponentManager = lpfnCM;
  192. }
  193.  
  194.  
  195. // Function FixupTB: Establish direct linkage to Movie Toolbox
  196. // -----------------------------------------------------------
  197. static VOID FAR PASCAL FixupTB (ENTRYFUNC lpfnTB) {
  198.  
  199.     lpfnQTToolbox = lpfnTB;
  200. }
  201.  
  202.  
  203. // Function GetInstOfThisMod: Get the instance handle of this module
  204. // -----------------------------------------------------------------
  205. static HINSTANCE GetInstOfThisMod () {
  206.  
  207.     return hInstThisMod;
  208. }
  209.  
  210.  
  211. // Function IdentifyP9000: Identify P9000
  212. // --------------------------------------
  213. extern "C" BOOL FAR PASCAL IdentifyP9000 (PP9000 pp9) {
  214.  
  215.     // Determine name of P9000 INI file
  216.     static char szINI[256], szTemp[256], FAR *p;
  217.     p = GetDOSEnvironment();
  218.     while (*p != 0) {
  219.         lstrcpy (szTemp, p);
  220.         AnsiUpper (szTemp);
  221.         if (_fmemcmp (szTemp, "VIPERPATH=", 10) == 0) {
  222.             lstrcpy (szINI, szTemp + 10);
  223.             if (szINI[lstrlen (szINI) - 1] == ';')
  224.                 szINI[lstrlen (szINI) - 1] = 0;
  225.             if (szINI[lstrlen (szINI) - 1] != '\\')
  226.                 lstrcat (szINI, "\\");
  227.             break;
  228.         }
  229.         else p += lstrlen (p) + 1;
  230.     }
  231.     if (*p == 0)
  232.         lstrcpy (szINI, "c:\\viper\\");
  233.     lstrcat (szINI, "viper.ini");
  234.  
  235.     // Determine base physical address
  236.     static char szBuffer[8], *q;
  237.     GetPrivateProfileString ("hardware", "memaddr", "0", szBuffer, sizeof szBuffer, szINI);
  238.     static DWORD dwMem = strtoul (szBuffer, &q, 16);
  239.     if (dwMem == 0)
  240.         return FALSE;
  241.     else pp9->dwPhysical = (dwMem << 16) + 0x200000L;
  242.  
  243.     // Determine memory size
  244.     static WORD wSize = GetPrivateProfileInt ("hardware", "memsize", 0, szINI);
  245.     if (wSize == 0)
  246.         return FALSE;
  247.     else pp9->dwMemory = (DWORD) wSize * 0x100000L;
  248.  
  249.     // Determine scan line width
  250.     static HDC hDC = GetDC (NULL);
  251.     static int iDepth = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
  252.     static int iWidth = GetDeviceCaps (hDC, HORZRES);
  253.     ReleaseDC (NULL, hDC);
  254.     pp9->wScanLineWidth = (iDepth * iWidth) >> 3;
  255.  
  256.     // Return OK
  257.     return TRUE;
  258.  
  259. }
  260.  
  261.  
  262. // Function LibMain: DLL Initialization
  263. // ------------------------------------
  264. int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) {
  265.  
  266.     // Perform common initialization
  267.     if (wHeapSize > 0)
  268.         UnlockData(0);
  269.     hInstThisMod = hInstance;
  270.  
  271.     // Successful return
  272.     return 1;
  273. }
  274.  
  275.  
  276. // Function THNGIDENTIFY: Entry point called by Component Manager; the function fills the Component ID structure
  277. // -------------------------------------------------------------------------------------------------------------
  278. extern "C" OSType FAR PASCAL THNGIDENTIFY (LPCID FAR *lplpcid) {
  279.  
  280.     // Allocate memory for CID information; the memory will be freed by the Component Manager
  281.     LPCID lpcid =  (LPCID) GlobalAllocPtr (GHND, sizeof CID);
  282.     if (lpcid == 0)
  283.         return 0;
  284.  
  285.     // Fill the structure
  286.     lpcid->lVersion = CID_VERSION;
  287.     lpcid->sComponentCount = 1;
  288.     lpcid->lpcdTable =  (LPCD) &cdTable;
  289.     lpcid->lpfnTBFixup = FixupTB;
  290.     lpcid->lpfnCMFixup = FixupCM;
  291.     *lplpcid = lpcid;
  292.  
  293.     // Return to caller
  294.     return THING;
  295. }
  296.  
  297.  
  298. // Function WEP: Windows DLL exit procedure
  299. // ----------------------------------------
  300. #pragma check_stack( off)
  301. extern "C" BOOL FAR PASCAL WEP (int nExitType) {
  302.  
  303.     // Clean up as requried by the adapter
  304.     if (CheckHardware != 0)
  305.         CheckHardware (VDSP_TERMINATE) ;
  306.  
  307.     // successful return
  308.     return TRUE ;
  309. }
  310. #pragma check_stack()
  311.